/***** Serendipity Booksellers -- btree.cpp *****/

#include "stdafx.h"
#include "btree.h"

/*************************************************************************************
 *                       BTREE::inorder                                              *
 *	Performs an inorder traverals of binary search tree of iterators                 *
 *************************************************************************************/
void BTREE::inorder(BNODE *tree)
{
	if (tree)
	{
		inorder(tree->left);
		tree->iter->bookInfo();
		inorder(tree->right);
	}
}

/*************************************************************************************
 *                       BTREE::insert                                               *
 *	Takes a binary search tree and an interator pointing to an item stored in a list *
 *	and inserts the iterator into the binary serach tree.                            *
 *************************************************************************************/
BNODE *BTREE::insert(BNODE *tree, list<BookData>::iterator iter)
{
	if (tree == NULL) return new BNODE(iter);
	if (iter->getWholesale() < tree->iter->getWholesale())
		tree->left = insert(tree->left, iter);
	else
		tree->right = insert(tree->right, iter);
	return tree;
}